#ifndef _MCL_MACROS_H_
#define _MCL_MACROS_H_

// bit operations
#define MCL_BIT_ENABLED(v, bit)  ((v) & (bit))
#define MCL_BIT_DISABLED(v, bit) (!((v) & (bit)))

#define MCL_SET_BITS(v, bits) (v |= (bits))
#define MCL_CLR_BITS(v, bits) (v &= ~(bits))

// safe delete
#define MCL_SAFE_DELETE(p)  \
    do                      \
    {                       \
        delete p;           \
        p = 0;              \
    } while (0)

#define MCL_SAFE_DELETE_ARRAY(p) \
    do                           \
    {                            \
        delete[] p;              \
        p = 0;                   \
    } while (0)

#define MCL_ROUND_SIZE(S, n) (((S) + (n) - 1) & ~((n) - 1))

// min max
#define MCL_MIN(a, b) ((a) < (b) ? (a) : (b))

#define MCL_MAX(a, b) ((a) > (b) ? (a) : (b))

// assertion
#include <assert.h>

#if defined(MCL_WIN)

#define MCL_ASSERT assert

#else

#ifdef NDEBUG
#   define MCL_ASSERT(expr) ((void)0)
#else
#   define MCL_ASSERT(expr) \
        (void)( (expr) || (printf("ASSERTION: %s:%u:%s: '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr) && ((int (*)())0)()) )
#endif

#endif // end of assertion

#endif
